package org.huntaway.struts1.preprocessor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.huntaway.struts.bean.RequestBean;
import org.huntaway.struts.bean.ServiceBean;
import org.huntaway.webtools.preprocessor.imp.BasePreprocessor;

public abstract class StrutsPreprocessor extends BasePreprocessor{
	protected ServiceBean serBean = new ServiceBean();

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(SUCC);
		return serBean;
	}

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean addBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(INPUT);
		return serBean;
	}

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean addProcess(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(SUCC);
		return serBean;
	}

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean editBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(INPUT);
		return serBean;
	}

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean editProcess(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(SUCC);
		return serBean;
	}

	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ServiceBean delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ServiceBean serBean = new ServiceBean();
		serBean.setTarget(SUCC);
		return serBean;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.huntaway.struts.service.SuperService#treRequestBean(javax.servlet
	 * .http.HttpServletRequest, org.huntaway.struts.bean.RequestBean)
	 */
	public RequestBean treRequestBean(HttpServletRequest request,
			RequestBean requestBean) {
		String pagetype = request.getParameter("pagetype");
		String method = requestBean.getServiceMethod();
		if (method.equals("add") || method.equals("edit")) {
			if (pagetype == null || pagetype.equals("")
					|| pagetype.equals("input") || pagetype.equals("list")) {
				requestBean.setServiceMethod(method + "Begin");
			} else {
				requestBean.setServiceMethod(method + "Process");
			}
		}
		return requestBean;
	}
}
